Open
Conversation
Owner
|
Plz add a picture of how it looks like in client |
Crystalwarrior
requested changes
Jul 21, 2024
| set_font(ui_vp_showname, "", "showname", p_char); | ||
| set_font(ui_vp_message, "", "message", p_char); | ||
| set_font(ui_ic_chatlog, "", "ic_chatlog", p_char); | ||
| set_font(ui_ic_chatlog_pinned, "", "ic_chatlog_pinned", p_char); |
Owner
There was a problem hiding this comment.
add ic_chatlog_pinned to the description so it's known what should be added to themes
Comment on lines
+4033
to
+4183
| void Courtroom::append_pinned_text(QString p_text, QString p_name, QString p_action, int color, bool selfname, QDateTime timestamp) | ||
| { | ||
| QColor chatlog_color = ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini"); | ||
| QTextCharFormat bold; | ||
| QTextCharFormat normal; | ||
| QTextCharFormat italics; | ||
| QTextCharFormat own_name; | ||
| QTextCharFormat other_name; | ||
| QTextCharFormat timestamp_format; | ||
| QTextCharFormat selftimestamp_format; | ||
| QTextBlockFormat format; | ||
| bold.setFontWeight(QFont::Bold); | ||
| normal.setFontWeight(QFont::Normal); | ||
| italics.setFontItalic(true); | ||
| own_name.setFontWeight(QFont::Bold); | ||
| own_name.setForeground( | ||
| ao_app->get_color("ic_chatlog_selfname_color", "courtroom_fonts.ini")); | ||
| other_name.setFontWeight(QFont::Bold); | ||
| other_name.setForeground( | ||
| ao_app->get_color("ic_chatlog_showname_color", "courtroom_fonts.ini")); | ||
| timestamp_format.setForeground( | ||
| ao_app->get_color("ic_chatlog_timestamp_color", "courtroom_fonts.ini")); | ||
| selftimestamp_format.setForeground(ao_app->get_color( | ||
| "ic_chatlog_selftimestamp_color", "courtroom_fonts.ini")); | ||
| format.setTopMargin(log_margin); | ||
| const QTextCursor old_cursor = ui_ic_chatlog_pinned->textCursor(); | ||
| const int old_scrollbar_value = ui_ic_chatlog_pinned->verticalScrollBar()->value(); | ||
| const bool need_newline = !ui_ic_chatlog_pinned->document()->isEmpty(); | ||
| const int scrollbar_target_value = | ||
| log_goes_downwards ? ui_ic_chatlog_pinned->verticalScrollBar()->maximum() | ||
| : ui_ic_chatlog_pinned->verticalScrollBar()->minimum(); | ||
|
|
||
|
|
||
| ui_ic_chatlog_pinned->moveCursor(log_goes_downwards ? QTextCursor::End | ||
| : QTextCursor::Start); | ||
|
|
||
| // Only prepend with newline if log goes downwards | ||
| if (log_goes_downwards && need_newline) { | ||
| ui_ic_chatlog_pinned->textCursor().insertBlock(format); | ||
| } | ||
|
|
||
| // Timestamp if we're doing that meme | ||
| if (log_timestamp) { | ||
| // Format the timestamp | ||
| QTextCharFormat format = selfname ? selftimestamp_format : timestamp_format; | ||
| if (timestamp.isValid()) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText( | ||
| "[" + timestamp.toString(log_timestamp_format) + "] ", format); | ||
| } | ||
| else { | ||
| qCritical() << "could not insert invalid timestamp" << timestamp; | ||
| } | ||
| } | ||
|
|
||
| // Format the name of the actor | ||
| QTextCharFormat name_format = selfname ? own_name : other_name; | ||
| ui_ic_chatlog_pinned->textCursor().insertText("📌" + p_name + "📌", name_format); | ||
| // Special case for stopping the music | ||
| if (p_action == tr("has stopped the music")) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + ".", normal); | ||
| } | ||
| // Make shout text bold | ||
| else if (p_action == tr("shouts") && log_ic_actions) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + " ", normal); | ||
| if (log_colors) { | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml( | ||
| "<b>" + | ||
| filter_ic_text(p_text, true, -1, 0) | ||
| .replace("$c0", chatlog_color.name(QColor::HexArgb)) + | ||
| "</b>"); | ||
| } | ||
| else | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_text, italics); | ||
| } | ||
| // If action not blank: | ||
| else if (p_action != "" && log_ic_actions) { | ||
| // Format the action in normal | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action, normal); | ||
| if (log_newline) | ||
| // For some reason, we're forced to use <br> instead of the more sensible | ||
| // \n. Why? Because \n is treated as a new Block instead of a soft newline | ||
| // within a paragraph! | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml("<br>"); | ||
| else | ||
| ui_ic_chatlog_pinned->textCursor().insertText(": ", normal); | ||
| // Format the result in italics | ||
| ui_ic_chatlog->textCursor().insertText(p_text + ".", italics); | ||
| } | ||
| else { | ||
| if (log_newline) { | ||
| // For some reason, we're forced to use <br> instead of the more sensible | ||
| // \n. Why? Because \n is treated as a new Block instead of a soft newline | ||
| // within a paragraph! | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml("<br>"); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(": ", normal); | ||
| } | ||
| // Format the result according to html | ||
| if (log_colors) { | ||
| QString p_text_filtered = filter_ic_text(p_text, true, -1, color); | ||
| p_text_filtered = | ||
| p_text_filtered.replace("$c0", chatlog_color.name(QColor::HexArgb)); | ||
| for (int c = 1; c < max_colors; ++c) { | ||
| QColor color_result = default_color_rgb_list.at(c); | ||
| p_text_filtered = p_text_filtered.replace( | ||
| "$c" + QString::number(c), color_result.name(QColor::HexArgb)); | ||
| } | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml(p_text_filtered); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(filter_ic_text(p_text, false), | ||
| normal); | ||
| } | ||
| } | ||
|
|
||
| // Only append with newline if log goes upwards | ||
| if (!log_goes_downwards && need_newline) { | ||
| ui_ic_chatlog_pinned->textCursor().insertBlock(format); | ||
| } | ||
|
|
||
| // If we got too many blocks in the current log, delete some. | ||
| while (ui_ic_chatlog_pinned->document()->blockCount() > log_maximum_blocks && | ||
| log_maximum_blocks > 0) { | ||
| QTextCursor temp_curs = ui_ic_chatlog_pinned->textCursor(); | ||
| temp_curs.movePosition(log_goes_downwards ? QTextCursor::Start | ||
| : QTextCursor::End); | ||
| temp_curs.select(QTextCursor::BlockUnderCursor); | ||
| temp_curs.removeSelectedText(); | ||
| if (log_goes_downwards) | ||
| temp_curs.deleteChar(); | ||
| else | ||
| temp_curs.deletePreviousChar(); | ||
| } | ||
|
|
||
| // Finally, scroll the scrollbar to the correct position. | ||
| if (old_cursor.hasSelection() || | ||
| old_scrollbar_value != scrollbar_target_value) { | ||
| // The user has selected text or scrolled away from the bottom: maintain | ||
| // position. | ||
| ui_ic_chatlog_pinned->setTextCursor(old_cursor); | ||
| ui_ic_chatlog_pinned->verticalScrollBar()->setValue(old_scrollbar_value); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->verticalScrollBar()->setValue( | ||
| log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : 0); | ||
| } | ||
| } | ||
|
|
||
| void Courtroom::clear_pinned_message() { ui_ic_chatlog_pinned->clear(); } | ||
|
|
Owner
There was a problem hiding this comment.
🚨 COPY PASTE ALERT 🚨
please revise, never copy-paste this much code! Adjust the existing function(s) instead and refactor them to allow your use case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PM Packet = send_command("PM", text, char_name, action) Set a pinned message in pinned message chatlog
CPM Packet = send_command("CPM") clear all the pinned messages